package jiejie.qiye;

import java.util.HashMap;

public class haiweilai {
    public static void main(String[] args) {
        int[] nums={1,3,5,8};
        int target=9;
        twoSum(nums,target);

    }

    public static int[] twoSum(int[] nums, int target) {
        if(nums==null||nums.length==0)
            return nums;
        HashMap<Integer,Integer> map = new HashMap<>();
        for(int i=0; i<nums.length; i++){
            map.put(nums[i],i);
        }
        for(int i=0; i<nums.length; i++){
            if(map.containsKey(target-nums[i])){
                return new int[]{i, map.get(target-nums[i])};
            }
        }
        //return null;
        return null;
    }
}